package com.clickpaas.workinghours.service.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.d20210220155135.model.*;
import com.clickpaas.workinghours.dao.LeadDao;
import com.clickpaas.workinghours.entity.LeadEntity;
import com.clickpaas.workinghours.service.LeadService;
import com.clickpaas.workinghours.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class LeadServiceImpl implements LeadService {
    @Resource
    private LeadDao leadDao;

    /**
     * 获取数据
     *
     * @param entity
     * @return
     */
    @Override
    public List<LeadDTO> getDataInfo(LeadEntity entity) {

        List<LeadDTO> reList;
        try {
            reList = DataInfoUtil.castListCopy(leadDao.queryDataInfo(entity), LeadDTOResponse.class, LeadDTO.class);
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",entity,e);
            return null;
        }
        if (null != reList && reList.size()>0){
            return reList;
        }
        return null;
    }

    /**
     * 项目数据转换为bean
     *
     * @param list
     * @return
     */
    @Override
    public List<LeadEntity> DataConver(List<LeadDTO> list) {
        return DataInfoUtil.castListCopy(list,LeadDTO.class,LeadEntity.class);
    }

    /**
     * 线索数据删除
     *
     * @param delete
     * @return
     */
    @Override
    public boolean deleteDataInfo(LeadEntity delete) {
        return leadDao.deleteDataInfo(delete);
    }

    /**
     * 线索数据更新
     *
     * @param query
     * @param update
     * @return
     */
    @Override
    public LeadSaveOrUpdateDataResponseObject updateDataInfo(LeadEntity query, LeadEntity update) {
        return leadDao.updateDataInfo(query,update);
    }

}
